<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller {
	public function news(){
		// banner:
		$banner=M('banner');
    	$bannerlist=$banner->select();
    	$this->assign('bannerlist',$bannerlist);

    	// 新闻资讯：
    	$newsinfo=M('newsinfo');
        // 方法1：（方法2：ajax）
        // var_dump($_GET['type']);
        // if (empty($_GET['type'])) {
        //     $type = 4;
        // } else {
        //     $type = $_GET['type'];
        // }
        // // isset($type) ? $_GET['type'] : 1; //isset($value) ? $value : 'No value set.';
        // $this->assign('type',$type);
        // $newsData=$newsinfo->where("type=".$type)->select();
        $newsData=$newsinfo->where("type=4")->order('newsDate desc')->limit(3)->select();
        $hotnewsData=$newsinfo->where("type=1")->order('newsDate desc')->limit(3)->select();
        //var_dump($newsData);
        $this->assign('hotnewsData',$hotnewsData);
        $this->assign('newsData',$newsData);
        $this->display();
    }

    public function getAjax(){
        $type=$_POST['type'];
        $newsinfo=M('newsinfo');
        $data=$newsinfo->where("type=".$type)->order('newsDate desc')->limit(3)->select();
        $this->ajaxReturn($data);
    }

}